package com.letme.web.controller.wxConfig;

import com.letme.common.annotation.Log;
import com.letme.common.core.controller.BaseController;
import com.letme.common.core.domain.AjaxResult;
import com.letme.common.core.domain.entity.WxUser;
import com.letme.common.core.page.TableDataInfo;
import com.letme.common.enums.BusinessType;
import com.letme.common.utils.poi.ExcelUtil;
import com.letme.store.service.IWxUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信登录用户Controller
 *
 * @Description
 * @Author lock-xq
 * @Date 2025/9/11 17:47
 **/
@RestController
@Tag(name = "微信登录用户")
@RequestMapping("/wx/wxUser")
public class WxUserController extends BaseController {
    @Resource
    private IWxUserService wxUserService;

    /**
     * 查询微信登录用户列表
     */
    @Operation(summary ="查询微信登录用户列表")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxUser wxUser)
    {
        startPage();
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        return getDataTable(list);
    }

    /**
     * 导出微信登录用户列表
     */
    @Operation(summary ="导出微信登录用户列表")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:export')")
    @Log(title = "微信登录用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxUser wxUser)
    {
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        ExcelUtil<WxUser> util = new ExcelUtil<>(WxUser.class);
        util.exportExcel(response, list, "微信登录用户数据");
    }

    /**
     * 获取微信登录用户详细信息
     */
    @Operation(summary ="获取微信登录用户详细信息")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:query')")
    @GetMapping(value = "/{wxUserId}")
    public AjaxResult getInfo(@PathVariable("wxUserId") Long wxUserId)
    {
        return success(wxUserService.selectWxUserByWxUserId(wxUserId));
    }

    /**
     * 新增微信登录用户
     */
    @Operation(summary ="新增微信登录用户")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:add')")
    @Log(title = "微信登录用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxUser wxUser)
    {
        return toAjax(wxUserService.insertWxUser(wxUser));
    }

    /**
     * 修改微信登录用户
     */
    @Operation(summary ="修改微信登录用户")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:edit')")
    @Log(title = "微信登录用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxUser wxUser)
    {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }

    /**
     * 删除微信登录用户
     * 逻辑删除，删除后不显示，但还存在数据库中
     * @param wxUserIds
     * @return
     */
    @Operation(summary ="批量删除微信登录用户--逻辑删除")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:remove')")
    @Log(title = "微信登录用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wxUserIds}")
    public AjaxResult remove(@PathVariable Long[] wxUserIds)
    {
        return toAjax(wxUserService.fakeDelWxUserByWxUserIds(wxUserIds));
    }

    /**
     * 删除微信登录用户
     * 真删除，删除后数据库不存在
     * @param wxUserIds
     * @return
     */
    @Operation(summary ="批量删除微信登录用户--真删除")
    @PreAuthorize("@ss.hasPermi('wx:wxUser:realRemove')")
    @Log(title = "微信登录用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/realDel/{wxUserIds}")
    public AjaxResult realRemove(@PathVariable Long[] wxUserIds)
    {
        return toAjax(wxUserService.realDelWxUserByWxUserIds(wxUserIds));
    }
}
